package com.xyazm.order.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xyazm.common.dao.BaseDAO;
import com.xyazm.order.domain.entity.AfterSaleRefundDO;
import com.xyazm.order.mapper.AfterSaleRefundMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 售后退款单表 DAO
 * @author xuyou
 * @date: 2022/6/29 14:49
 */
@Repository
public class AfterSaleRefundDAO extends BaseDAO<AfterSaleRefundMapper, AfterSaleRefundDO> {

    /**
     * 根据售后单号查询售后退款记录
     * @author xuyou
     * 2022-12-06 22:37
     * @param afterSaleId 售后单号
    */
    public AfterSaleRefundDO getOneByAfterSaleId(String afterSaleId) {
        LambdaQueryWrapper<AfterSaleRefundDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AfterSaleRefundDO::getAfterSaleId, afterSaleId);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据售后单号查询售后单退款记录
     * @author xuyou
     * @date: 2022/7/21 16:53
     * @param: afterSaleId
     */
    public List<AfterSaleRefundDO> listByAfterSaleId(String afterSaleId) {
        LambdaQueryWrapper<AfterSaleRefundDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AfterSaleRefundDO::getAfterSaleId, afterSaleId);
        return list(queryWrapper);
    }


    public void updateAfterSaleRefundStatus(AfterSaleRefundDO afterSaleRefundDO) {
        LambdaUpdateWrapper<AfterSaleRefundDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(AfterSaleRefundDO::getAfterSaleId, afterSaleRefundDO.getAfterSaleId());
        update(afterSaleRefundDO, updateWrapper);
    }

}
